#Requires AutoHotkey v2.0

global KeyWaitTime := 300    ;长按时间
global VideoPage := 0        ;视频窗口WinID
global WindowSize := 800     ;窗口大小,位置 

global WindowMap := Map(     ;激活窗口的key
  "q" , 0,  
  "w" , 0,  
  "e" , 0,  
  "r" , 0,  
  "z" , 0,  
  "x" , 0,  
  "c" , 0,  
  "v" , 0,  
  "b" , 0,
)


;长按提示
longPress() {
 WinHide("A")
 Sleep 50
 WinShow("A")
}

; 窗口透明度
increaseWindowOpacity(){
  winOpacity := WinGetTransparent("A")? WinGetTransparent("A") : 255
  if(winOpacity <= 204){
    WinSetTransparent(winOpacity + 51, "A")
  } else {
    WinSetTransparent(255, "A")
  }
}

reduceWindowOpacity() {
  winOpacity := WinGetTransparent("A")? WinGetTransparent("A") : 255
  if(winOpacity >= 51){
    WinSetTransparent(winOpacity - 51, "A")
  } else {
    WinSetTransparent(0, "A")
  }
}



; 置顶 / 窗口最大化
topOrMaxWindow(letter){
  SetTimer longPress, "-" . KeyWaitTime
  keywait letter
  winTitle := WinGetTitle('A')
  if (A_TimeSinceThisHotkey < KeyWaitTime) {
    WinGetMinMax("A") == 1 ? WinRestore("A") : Winmaximize("A")
  } else {
    winsetalwaysontop(-1, winTitle)
    ExStyle := WinGetExStyle(wintitle)
    if (ExStyle & 0x8) {
      OnlyInput.fixedTip("⬛ 置顶 " . wintitle, 1000)
    } else {
      OnlyInput.fixedTip("⚫ 取消置顶 " . wintitle, 1000)
    }
  }
}

; 设置窗口宽度
defineWindowSize(num) {
  global WindowSize := num
}

; 改变窗口大小和位置
WinMoveFunction() {
  global WindowSize
  static winPos := 1
  WinRestore("A") 
  if (A_ScreenWidth > A_ScreenHeight) {
    winPos ? WinMove(A_ScreenWidth-WindowSize, 0, WindowSize, A_ScreenHeight, "A") : WinMove(0, 0, WindowSize, A_ScreenHeight, "A") 
  } else {
    winPos ? WinMove(0, (A_ScreenHeight - WindowSize), A_ScreenWidth, WindowSize, "A") : WinMove(0, 0, A_ScreenWidth, WindowSize , "A")  
  }
  winPos := !winPos
}

;激活窗口
WindowManager(key){
  global
  SetTimer longPress, "-" . KeyWaitTime
  keywait key
  if (A_TimeSinceThisHotkey > KeyWaitTime) {
      WindowMap[key] := WinGetID("A")
    OnlyInput.fixedTip(WinGetTitle("A"), 1000)
  } else {
    SetTimer longPress, 0
    if WinExist(WindowMap[key]){
      mediaPlayPause() 
      (WinActive(WindowMap[key])) ? winminimize("A") : WinActivate(WindowMap[key])
      mediaPlayPause() 
    }else {
      OnlyInput.fixedTip("未设置", 500)
    }
  }
}
